﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Zwms.Data.BusinessObjects;
using Zwms.Client.CommonUI;

namespace Zwms.Client.ManageWms
{
    public partial class NewCountBillForm : BaseForm
    {
        #region 成员变量
        private BilCountBill _currentRecord;
        public BilCountBill CurrentRecord { get { return this._currentRecord; } }
        #endregion

        #region 构造函数
        public NewCountBillForm()
        {
            InitializeComponent();
            InitBtnImage();
            this.tbsWarehouse.Tag = MainForm.CurrentUser.WarehouseCode;
            this.tbsWarehouse.SetTextBoxContent(MainForm.CurrentUser.WarehouseName);
            if (MainForm.CurrentUser.UserRole.Trim() == "03")
            {
                this.tbsWarehouse.SetEditState(false);
            }
            else
            {
                this.tbsWarehouse.SetEditState(true);
            }
            InitCountBillCode();
        }
        #endregion

        #region 私有函数

        private void InitBtnImage()
        {
            this.btnConfirm.Image = global::Zwms.Client.Properties.Resources.ok;
            this.btnCancel.Image = global::Zwms.Client.Properties.Resources.cancel;
        }

        private void InitCountBillCode()
        {
            ServiceReferenceZwms.ServiceZwmsClient client = new ServiceReferenceZwms.ServiceZwmsClient();
            tbCountBillCode.Text = client.InitCountBillCode();
        }
        #endregion

        #region 控件函数
        private void btnConfirm_Click(object sender, EventArgs e)
        {
            //数据完整性检查
            bool bRet = true;
            if (string.IsNullOrWhiteSpace(tbsWarehouse.GetTextBoxContent()))
            {
                bRet = false;
                tbsWarehouse.SetTextBGColor(Color.Yellow);
            }
            if (dpuPlanCountDate.SelectDateTime == null)
            {
                bRet = false;
                dpuPlanCountDate.SetTextBGColor(Color.Yellow);
            }
            if (!bRet)
            {
                return;
            }
            if (MessageBox.Show("是否确认添加该入库计划单？", "确认", MessageBoxButtons.OKCancel) == DialogResult.OK)
            {
                this._currentRecord = new BilCountBill();
                _currentRecord.Id = tbCountBillCode.Text.Trim();
                _currentRecord.PlanCountDate = dpuPlanCountDate.SelectDateTime;
                if (!string.IsNullOrWhiteSpace(tbsWarehouse.GetTextBoxContent()))
                {
                    _currentRecord.WarehouseName = tbsWarehouse.GetTextBoxContent();
                    _currentRecord.WarehouseCode = tbsWarehouse.Tag.ToString();
                }
                _currentRecord.BillStatus = "1";
                _currentRecord.IsDeactived = "0";
               ServiceReferenceZwms.ServiceZwmsClient client1 = new ServiceReferenceZwms.ServiceZwmsClient();
                DateTime dtNow = client1.GetCurrentSystemTime();
                _currentRecord.CreateUserName = MainForm.CurrentUser.UserName;
                _currentRecord.CreateUserCode = MainForm.CurrentUser.Id;
                _currentRecord.CreateDate = Helper.CommonHelper.GetDateString(dtNow);
                _currentRecord.CreateTime = Helper.CommonHelper.GetTimeString(dtNow);

                this.DialogResult = DialogResult.OK;
            }
            else
            {
                return;
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void tbsWarehouse_SelectButtonClick(object sender, EventArgs e)
        {
            InfoWms.WarehouseWnd uc = new InfoWms.WarehouseWnd();
            CommonUI.ContainerForm window = new CommonUI.ContainerForm(uc, "选择收货仓库");
            uc.SetQueryState();
            if (window.ShowDialog() == System.Windows.Forms.DialogResult.OK)
            {
                tbsWarehouse.SetTextBoxContent(uc.SelectedRecord.WarehouseName);
                tbsWarehouse.Tag = uc.SelectedRecord.Id;
            }
        }
        #endregion
    }
}
